var vm_customedit = new Vue({
    el : "#customedit ",
    data : {
        userid : $("#userid").val(),
        olddeptid : $("#olddeptid").val(),		// deptid
        roleid : $("#roleid").val(),		// deptid
        dept : {},//单位

        diqusearch:"",

        //add字段
        userItem:{
            loginName: "",
            phonenumber: "",
            email: "",
            userName:"",
            text1:"",//所属部门
            text2:"",//办公电话
            remark:""
        },

    },
    created : function(){
        var _this = this;

        _this.bindUser();
        _this.bindDept();

    },
    methods : {
        bindUser:function(){
            var _this = this;
            var dept_layer = layer.open({type: 3});
            $.post('/system/user/findone', {
                userid: _this.userid,
                rdm: Math.random()
            }, function (ppData) {
                layer.close(dept_layer);
                if (ppData != null) {

                    if(ppData.result == "1"){
                        _this.userItem = ppData.resultContent;
                    }else{
                        layer.alert(ppData.message);
                    }

                }
            }, "json");
        },
        searchdiqu: function () {
            var _this = this;
            $.post('/system/deptdetail/searchdiqu', {
                diqu: _this.diqusearch,
                rdm: Math.random()
            }, function (ppData) {
                if (ppData != null) {

                    if (ppData.result == "1") {
                        $("#beizhu1").html("");

                        var diqulist = ppData.resultContent;
                        for (var i=0;i<diqulist.length;i++){
                            $("#beizhu1").append("<option value='"+ diqulist[i].dict_label +"' >"+ diqulist[i].dict_label +"</option>");
                        }

                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },
        // 保存单位信息
        saveUser : function(){
            var _this = this;
            var dept_layer = layer.open({type: 3});
            $.post('/system/user/ModalEdit', {
                userId:_this.userid,
                phonenumber:_this.userItem.phonenumber,
                email:_this.userItem.email,
                userName:_this.userItem.userName,
                loginName:_this.userItem.loginName,
                text1:_this.userItem.text1,//所属部门
                text2:_this.userItem.text2,//办公电话
                remark:_this.userItem.remark,
                rdm: Math.random()
            }, function (ppData) {
                layer.close(dept_layer);
                if (ppData != null) {

                    if(ppData.code == "0"){
                        layer.open({
                            time: 1000,
                            btn: [],
                            content: ppData.msg,
                        });
                    }else{
                        layer.alert(ppData.msg);
                    }

                }
            }, "json");
        },
        resetPwd:function () {
            var url = 'system/user/yonghuguanli/resetPwd/' + this.userid;
            $.modal.open("重置密码", url, '800', '300');
        },
        bindDept : function(){
            var _this = this;

            var dept_layer = layer.open({type:3});
            $.post('/system/deptdetail/findone', {
                deptid : _this.olddeptid,
                rdm : Math.random()
            },function(ppData) {
                layer.close(dept_layer);

                if(ppData != null){

                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.dept = data;
                        _this.dept.deptid = _this.olddeptid;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        // 保存单位信息
        save : function(){
            var _this = this;
            if (_this.checkInputData()) {
                var dept_layer = layer.open({type: 3});
                $.post('/system/deptdetail/save', {
                    id: _this.olddeptid,
                    jigoumingcheng: _this.dept.jigoumingcheng,
                    jigoujibie: _this.dept.jigoujibie,
                    jigouleixing: _this.dept.jigouleixing,
                    shengfen: _this.dept.shengfen,
                    chengshi: _this.dept.chengshi,
                    dizhi: _this.dept.dizhi,
                    youbian: _this.dept.youbian,
                    chuanzhenghaoma: _this.dept.chuanzhenghaoma,
                    dianziyoujian: _this.dept.dianziyoujian,
                    jingbanren: _this.dept.jingbanren,
                    jingbanrenbangongdianhua: _this.dept.jingbanrenbangongdianhua,
                    jingbanrenshoujihaoma: _this.dept.jingbanrenshoujihaoma,
                    fuzeren: _this.dept.fuzeren,
                    fuzerenbangongdianhua: _this.dept.fuzerenbangongdianhua,
                    fuzerenshoujihaoma: _this.dept.fuzerenshoujihaoma,
                    caiwulianxiren: _this.dept.caiwulianxiren,
                    caiwubangongdianhua: _this.dept.caiwubangongdianhua,
                    caiwushoujihaoma: _this.dept.caiwushoujihaoma,
                    kaihuhang: _this.dept.kaihuhang,
                    kaihumingcheng: _this.dept.kaihumingcheng,
                    yinhangzhanghao: _this.dept.yinhangzhanghao,
                    yinhangdizhi: _this.dept.yinhangdizhi,
                    lianhanghao: _this.dept.lianhanghao,
                    beizhu1 : _this.dept.beizhu1,
                    rdm: Math.random()
                }, function (ppData) {
                    layer.close(dept_layer);
                    if (ppData != null) {

                        if(ppData.result == "1"){
                            layer.open({
                                time: 1000,
                                btn: [],
                                content: "保存成功!",
                            });
                        }else{
                            layer.alert(ppData.message);
                        }

                    }
                }, "json");
            }
        },

        //检查项目数据
        checkInputData : function() {
            if (!$.trim(this.dept.jigoumingcheng)) {
                layer.alert("请填写单位名称！");
                return false;
            }
            if (!$.trim(this.dept.jingbanren)) {
                layer.alert("请填写经办人！");
                return false;
            }
            if (!$.trim(this.dept.jingbanrenbangongdianhua)) {
                layer.alert("请填写经办人办公电话！");
                return false;
            }
            if (!$.trim(this.dept.jingbanrenshoujihaoma)) {
                layer.alert("请填写经办人手机号码！");
                return false;
            }
            if (!$.trim(this.dept.caiwulianxiren)) {
                layer.alert("请填写财务联系人！");
                return false;
            }
            if (!$.trim(this.dept.caiwubangongdianhua)) {
                layer.alert("请填写财务办公电话！");
                return false;
            }
            if (!$.trim(this.dept.caiwushoujihaoma)) {
                layer.alert("请填写财务手机号码！");
                return false;
            }
            if (!$.trim(this.dept.kaihuhang)) {
                layer.alert("请填写开户行！");
                return false;
            }
            if (!$.trim(this.dept.kaihumingcheng)) {
                layer.alert("请填写开户名称！");
                return false;
            }
            if (!$.trim(this.dept.yinhangzhanghao)) {
                layer.alert("请填写银行账号！");
                return false;
            }

            return true;
        },

    },
})